﻿using System;

namespace GLog
{
    public class BufferedCSVFileLog : BufferedTextFileLog
    {
        public BufferedCSVFileLog(string logFileName, ILog postLog = null, LogLevel displayLevel = LogLevel.Error|LogLevel.Message|LogLevel.Warning)
            : base(logFileName, postLog, displayLevel)
        {

        }

        public override void Initial()
        {
            base.Initial();
            Buffer.AppendFormat("{0},{1},{2}", "Time", "Level", "Details");
            Buffer.AppendLine();
        }

        internal override void LogMessage(string info, LogLevel level)
        {
            if (Buffer == null)
            {
                throw new InvalidOperationException("Log is not initialized.");
            }

            Buffer.AppendFormat("{0},{1},{2}", DateTime.Now, level.ToString(), info);
            Buffer.AppendLine();
        }

        protected override void OutputHeader(string message)
        {
            Buffer.AppendFormat("{0},{1},{2}", DateTime.Now, "Header", message);
            Buffer.AppendLine();
        }
    }
}
